<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name = "format-detection" content = "telephone=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
            height: 100%;
        }
        .main {
            /*padding: 6px 0;*/
            height: 100%;
        }
        .main ul li {
        	margin-bottom: 6px;
        }
        .order_info {
        	padding: 15px;
        	background-color: #fff;
        }
        .order_info .title_box {
        	display: -webkit-box;
        	display: -webkit-flex;
        	margin-bottom: 15px;
        }
        .order_info .title_box .title_boxl {
			width: 0;
			flex: 1;
			-webkit-flex: 1;
			box-flex: 1;
			-webkit-box-flex: 1;
        }
        .order_info .title_box .title_boxl .time {
        	font-size: 12px;
        	color: #999;
        }
        .order_info .title_box .title_boxr {
			color: #999;
			font-size: 13px;
			padding-top: 2px;
			padding-left: 5px;
        }
        .order_info .info_box {
        	font-size: 13px;
        	color: #333;
        }
        .order_info .info_box span {
        	color: #e62442;
        }
        .order_info .info_box .info {
        	padding-bottom: 10px;
        }
        .order_info .info_box .info span {
        	margin-left: 8px;
        }
		.order_info .info_box .address {
        	padding-bottom: 17px;
        }
        .order_info .goods_info {
        	display: -webkit-box;
        	display: -webkit-flex;
        	align-items: center;
        }
        .order_info .goods_info .goods_infol {
        	width: 0;
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	font-size: 12px;
        	color: #999;
        }
        .order_info .goods_info .goods_infor {
        	font-size: 17px;
        	color: #e62442;
        	padding-left: 5px;
        }
        .staff_info {
        	background-color: #fff;
        	padding: 0 14px;
        	border-top: 1px solid #e8e8e8;
        }
        .staff_info .staff_box {
        	height: 40px;
        	line-height: 40px;
        	overflow: hidden;
        }
        .staff_info .staff_box .staff_boxl {
        	height: 40px;
        	float: left;
        	display: -webkit-box;
        	-webkit-box-align: center;
        }
        .staff_info .staff_box .staff_boxl .img_box {
        	width: 21px;
        	height: 21px;
        	border-radius: 50%;
        	overflow: hidden;
        	margin-right: 5px;
        }
        .staff_info .staff_box .staff_boxl .img_box img {
			width: 100%;
			height: 100%;
			object-fit: cover;
			display: block;
        }
        .staff_info .staff_box .staff_boxl span {
        	font-size: 13px;
        	color: #999;
        	display: block;
        }
        .staff_info .staff_box .staff_boxr {
        	height: 40px;
        	float: right;
        	display: -webkit-box;
        	-webkit-box-align: center;
        }
        .staff_info .staff_box .staff_boxr img {
        	width: 13px;
        	display: block;
        }
        .confirm_box {
        	background-color: #fff;
        	margin-top: 6px;
        }
        .confirm_box .confirm_boxb {
        	overflow: hidden;
        	padding: 0 15px 15px;
        }
        .confirm_box .confirm_boxb .btn {
        	width: 67px;
        	height: 22px;
        	line-height: 22px;
        	float: right;
        	text-align: center;
        	border-radius: 5px;
			font-size: 12px;
			color: #333;
			border: 1px solid #999;
        }
        .staff_div {
        	padding: 15px;
        	display: -webkit-box;
        	display: -webkit-flex;
        }
        .staff_div .staff_divl .staff_img {
			width: 40px;
			height: 40px;
			border-radius: 50%;
			overflow: hidden;
			border: 1px solid #d3d3d3;
        }
        .staff_div .staff_divl .staff_img img {
        	width: 100%;
        	height: 100%;
        	object-fit: cover;
        }
        .staff_div .staff_divc {
        	width: 0;
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	padding: 0 10px;
        }
        .staff_div .staff_divc .name {
        	font-size: 15px;
        	color: #333;
        	margin-bottom: 6px;
        }
        .staff_div .staff_divc .phone {
        	color: #999;
        	font-size: 12px;
        	margin-bottom: 14px;
        }
        .staff_div .staff_divc .text_success {
        	color: #1abc5e;
        	font-size: 13px;
        	display: -webkit-box;
        	-webkit-box-align: center;
        }
        .staff_div .staff_divc .text_success img {
        	width: 14px;
        	margin-right: 5px;
        	display: block;
        }
        .staff_div .staff_divr .num_p {
			font-size: 12px;
			color: #999;
			margin-bottom: 10px;
			padding-top: 6px;
        }
        .staff_div .staff_divr .num {
			color: #f0b925;
			font-size: 16px;
        }
        .btn_box {
        	overflow: hidden;
        	background-color: #fff;
        	padding: 0 15px 15px;
        }
        .btn_box .btn {
        	width: 67px;
        	height: 22px;
        	line-height: 22px;
        	float: right;
        	text-align: center;
        	border-radius: 5px;
			font-size: 12px;
			color: #999;
			border: 1px solid #999;
        	background-color: #fff;
        	margin-left: 10px;
        }
        .loading{
            color: #ccc;
            text-align: center;
            line-height: 25px;
            display: none;
        }
        .hidden_img {
            display: none;
        }
    </style>
</head>
<body>
    <div class="main">
        <div class="without_data">暂无订单</div>
    	<ul id="order_ul">
    	<!-- 	<li>
    			<div class="order_info">
		    		<div class="title_box">
		    			<div class="title_boxl">
		    				<div class="time">2017--09-07 11:12:12</div>
		    			</div>
		    			<div class="title_boxr">已完成</div>
		    		</div>
		    		<div class="info_box">
		    			<div class="info">张先生<span>13333333333</span></div>
		    			<div class="address">北京市海淀区龙翔路泰祥商务楼508</div>
		    		</div>
		    		<div class="goods_info">
		    			<div class="goods_infol">鱼香肉丝、宫爆鸡丁等3样菜品</div>
		    			<div class="goods_infor">RM 29.5</div>
		    		</div>
		    	</div>
		    	<div class="staff_info">
		    		<div class="staff_box">
		    			<div class="staff_boxl">
		    				<div class="img_box">
		    					<img src="../image/temp/1.png">
		    				</div>
		    				<span>查看骑手信息</span>
		    			</div>
		    			<div class="staff_boxr">
		    				<img src="../image/bottom.png">
		    			</div>
		    		</div>
		    	</div>
		    	<div class="confirm_box">
	    			<div class="staff_div">
	    				<div class="staff_divl">
	    					<div class="staff_img">
	    						<img src="../image/temp/1.png">
	    					</div>
	    				</div>
	    				<div class="staff_divc">
	    					<div class="name">刘德华</div>
	    					<div class="phone">13333333333</div>
	    					<div class="text_success"><img src="../image/success.png">已确认骑手身份</div>
	    				</div>
	    				<div class="staff_divr">
	    					<div class="num_p">取餐码</div>
	    					<div class="num">65</div>
	    				</div>
	    			</div>
		    	</div>
		    	<div class="btn_box">
    				<div class="btn">已完成配送</div>
    			</div>
    		</li> -->
    	</ul>
        <div class="loading">loading...</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="orderTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li onclick="fnOrderDetail({{=it[i]['id']}},{{=it[i]['status']}});" tapmode>
            <div class="order_info">
                <div class="title_box">
                    <div class="title_boxl">
                        <div class="time">{{=it[i]['create_time']}}</div>
                    </div>
                    <div class="title_boxr">已完成</div>
                </div>
                <div class="info_box">
                    <div class="info">{{=it[i]['username']}}<span>{{=it[i]['tel']}}</span></div>
                    <div class="address">{{=it[i]['address_detail']}}</div>
                </div>
                <div class="goods_info">
                    <div class="goods_infol">
                        {{ if(it[i]['goods_type_count'] > 1){ }}
                            {{=it[i]['goods_name']}}等{{=it[i]['goods_type_count']}}样菜品
                        {{ }else{ }}
                            {{=it[i]['goods_name']}}
                        {{ }; }}
                    </div>
                    <div class="goods_infor">RM {{=it[i]['must_pay']}}</div>
                </div>
            </div>
                <div class="confirm_box">
                    <div class="staff_div">
                        <div class="staff_divl">
                            <div class="staff_img">
                                <img src="{{=formatHeadImg(it[i]['staff_img'])}}">
                            </div>
                        </div>
                        <div class="staff_divc">
                            <div class="name">{{=it[i]['staff_name']}}</div>
                            <div class="phone">{{=it[i]['staff_phone']}}</div>
                            <div class="text_success"><img src="../image/success.png">已确认骑手身份</div>
                        </div>
                        <div class="staff_divr">
                            <div class="num_p">取餐码</div>
                            <div class="num">{{=it[i]['order_code']}}</div>
                        </div>
                    </div>
                </div>
                <div class="btn_box">
                    <div class="btn">已完成配送</div>
                </div>
        </li>
    {{ }; }}
</script>
<script type="text/javascript">
    apiready = function(){
        shop = $api.getStorage('shop_data');
        order_status = api.pageParam.order_status;
        p = 1;
        canLoad = true;
        //上拉加载
        api.addEventListener({
            name:'scrolltobottom',
            extra:{
                threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err){
            if(canLoad) {
                p++;
                if($(window).scrollTop()) {
                    $(".loading").show();
                }
                fnGetOrder(2);
            }
        });

        //下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            p = 1;
            fnGetOrder(1);
            setTimeout(function(){
                api.refreshHeaderLoadDone();
            },1500);
        });

        //订单有了变化
        api.addEventListener({
            name: 'orderChangeEvent'
        }, function(ret, err) {
            if (ret) {
                p = 1;
                fnGetOrder(1);
            }
        });

        api.addEventListener({
            name: 'loginEvent'
        }, function(ret, err) {
            if (ret) {
                shop = $api.getStorage('shop_data');
                p = 1;
                fnGetOrder(1);
            }
        });
        fnGetOrder();
    };

    function fnGetOrder(type) {
        if(canLoad == false) {
            return;
        }
        canLoad = false;
        api.ajax({
            url: rootPath+'/api/seller_order/get_orders',
            method: 'get',
            cache: true,
            data: {
                values: { 
                    p:p,
                    shop_id : shop.id,
                    token: shop.token,
                    status: order_status,
                },
            }
        }, function(ret, err) {
            //type=1 下拉刷新，清除原来数据
            if(type == 1) {
                $('#order_ul').empty();
            }
            if (ret) {
                if(ret.status == 200) {
                    $('.without_data').hide();
                    $('.title_p').show();
                    appendDotData(ret.data,'orderTpl','order_ul',true);
                }else {
                    if(p == 1) {
                        $('.without_data').show();
                        $('.title_p').hide();
                    }
                }
            } else {
                showError(err.code,err.msg)
            }
            if(type == 1) {
                // 是下拉刷新的，要收回
                api.refreshHeaderLoadDone();
            }
            if(type == 2) {
                //上拉给点假时间,好看些         
                setTimeout(function(){
                    $(".loading").hide();
                },1000);
                setTimeout(function(){
                    canLoad = true;
                },1100)
            }else {
                $('.loading').hide();
                canLoad = true;
            }
            closeLoading();
        });
    }

    function fnOrderDetail(id,status) {
        if(status == 1 || status == 2 || status == 3 || status == 4) {
            api.openWin({
                name: 'order_detail2',
                url: './order_detail2.html',
                pageParam: {
                    id: id,
                    status : status
                }
            });
        }else{
            api.openWin({
                name: 'order_detail',
                url: './order_detail.html',
                pageParam: {
                    id: id,
                    status : status
                }
            });
        }
    }

    function fnConfirmOrder(order_id) {
        api.openWin({
            name: 'confirm_order',
            url: './confirm_order.html',
            pageParam: {
                id: order_id
            }
        });
        event.stopPropagation();
        return false;
    }

    function fnCheckRefund(order_id) {
        api.openWin({
            name: 'schedule',
            url: './schedule.html',
            pageParam: {
                id: order_id
            }
        });
        event.stopPropagation();
        return false;
    }

    function fnOpenSeller(shop_id) {
        api.openWin({
            name: 'seller',
            url: './seller.html',
            pageParam: {
                id: shop_id
            }
        });
    }

    function fnToComment(order_id) {
        api.openWin({
            name: 'release_evaluate_order',
            url: './release_evaluate_order.html',
            pageParam: {
                order_id: order_id
            }
        });
    }
</script>
</html>